<?php
/*code here*/
/* Redirect user if they already logged */
if(Auth::hasAuth('current_user'))
{
    $this->view->current_user = Auth::getAuth('current_user');

    header('location: /home');
}
/* For user login if correct redirect to home */
if($_SERVER['REQUEST_METHOD'] == "POST")
{
    
    
    $username = $_POST['username'];
    $password = $_POST['password'];
    $session = new Auth();
    $fs = new Database();
    $set_date = $fs->set_default_timezone_datetime();
    $db = new Database();
    $login = $session->login($username,$password,'username','password','tb_users');
    if($login)
    {
        if(isset($_GET['redirect_url'])){
            $decode_url = Functions::encode_decode_url($_GET['redirect_url'],"decode");
            header('Location: /' . $decode_url); 
        }else{
            header('Location: /home'); 
        }
        $fs->save_audit_logs($db,$login['id'],"1","tb_users",$set_date['date_time'],$login['id']);
    }
}   
/*code here(end)*/
$this->setLayout();